package com.example.j2025_11_10.service;

import com.example.j2025_11_10.Model.BookInfo;
import com.example.j2025_11_10.mapper.AddBookMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Slf4j
@Service
public class AddBookService {
    @Autowired
    public AddBookMapper addBookMapper;

    public String addBook(BookInfo bookInfo){
        log.info("参数输入错误: {}",bookInfo);
        if (bookInfo == null) {
            return "参数有误";
        }else if (!StringUtils.hasLength(bookInfo.getBookName())){
            return "书名格式不对";
        } else if (!StringUtils.hasLength(bookInfo.getAuthor())) {
            return "作者名字格式不对";
        } else if (!StringUtils.hasLength(bookInfo.getPublish())) {
            return "出版社名字格式不对";
        } else if (bookInfo.getCount() == null) {
            return "数量不能为0";
        } else if (bookInfo.getPrice() == null) {
            return "价格不能为空";
        }else if(bookInfo.getStatus() == null){
            return "请设置借阅状态";
        }else {
        addBookMapper.addBook(bookInfo);
        return "";
        }
    }

}
